package com.service.configration.imp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mapper.configration.DictionaryMapper;
import com.mapper.configration.TagMapper;
import com.po.TagInfo;
import com.po.DictionaryInfo;
import com.service.configration.TagService;
import com.util.UUIDGenerator;
@Service
public class TagServiceImp implements TagService{
    @Resource(name="tagMapper")
    private TagMapper tagMapper;
    @Resource(name="dictionaryMapper")
    private DictionaryMapper dictionaryMapper;
	@Override
	public List<TagInfo> getTagList(TagInfo tagInfo) {
		List<TagInfo> list=tagMapper.getTagList(tagInfo);
		return list;
	}

	@Override
	public int getTagCount(TagInfo tagInfo) {
		int i=tagMapper.getTagCount(tagInfo);
		return i;
	}

	@Override
	public int addTag(TagInfo tagInfo) {
		tagInfo.setTag_id(UUIDGenerator.getUUID());
		int i=tagMapper.addTag(tagInfo);
		return i;
	}

	@Override
	public int updateTag(TagInfo tagInfo) {
		int i=tagMapper.updateTag(tagInfo);
		
		return i;
	}

	@Override
	public int deleteTag(TagInfo tagInfo) {
		int i=tagMapper.deleteTag(tagInfo);
		DictionaryInfo dictionaryInfo=new DictionaryInfo();
		dictionaryInfo.setDictionary_id(tagInfo.getTag_id());
		int j=dictionaryMapper.deleteDictionary(dictionaryInfo);
		if(i==1&&j==1)
			return 1;
		else return 0;
	}

	@Override
	public int deleteTags(String[] ids) {
		int j=dictionaryMapper.deleteDictionarys(ids);
		int i=tagMapper.deleteTags(ids);
		
		if(i==1&&j==1)
			return 1;
		else return 0;
	}

	@Override
	public int getTagMax() {
		int i=tagMapper.getTagMax();
		return i;
	}
	@Override
	public List<TagInfo> getTagListN(String id) {
		List<TagInfo> list=tagMapper.getTagListN(id);
		return list;
	}

	@Override
	public List<TagInfo> getTagListByReczsk(String[] id) {
		List<TagInfo> list=tagMapper.getTagListByReczsk(id);
		return list;
	}
    //根据多个id字符串获取相应的Tag标签以及标签中的值
	@Override
	public List<TagInfo> getTagByIDS(String reczsk_id) {
		// TODO Auto-generated method stub
		String[] reczsk_ids = {};
		if (reczsk_id != "" && reczsk_id != null) {
			reczsk_ids = reczsk_id.split(",");
		}
		List<TagInfo> taglist = tagMapper.getTagListByReczsk(reczsk_ids);
		int i = 0;
		for (TagInfo tag : taglist) {
			DictionaryInfo dictionaryInfo = new DictionaryInfo();
			dictionaryInfo.setDictionary_id(tag.getTag_id());
			List<DictionaryInfo> dic_list = dictionaryMapper.getDictionaryList(dictionaryInfo);
			taglist.get(i).setList(dic_list);
			i++;
			dictionaryInfo=null;
		}
		return taglist;
	}
}
